package com.tianhui.consignortwofei.mvp.ui.activity.audit.vehicle;

import android.os.Bundle;
import android.text.TextUtils;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.entity.PictureInfo;
import com.fgs.common.widget.itemView.InputItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.mvp.model.enty.SelectPhotoInfo;
import com.tianhui.consignortwofei.mvp.model.enty.VehicleInfo;
import com.tianhui.consignortwofei.other.auth.PictureContext;
import com.tianhui.consignortwofei.other.auth.inte.SelectPhotoCallback;
import com.tianhui.consignortwofei.other.auth.stragety.VehicleFrontStrategy;

import butterknife.BindView;
import butterknife.OnClick;

public class VehicleTowedFrontAuditActivity extends BaseVehicleAuditActivity {

    @BindView(R.id.activity_vehicle_towed_front_audit_plateNumberInputItemView)
    InputItemView mPlateNumberInputItemView;

    private String mFrontTowedImageId;

    @Override
    public int getLayoutId() {
        return R.layout.activity_vehicle_towed_front_audit;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

    @Override
    public String getToolbarSubtitle() {
        return "跳过";
    }

    @Override
    public void onSubtitleClick() {
        openActivityForResult(VehicleTowedBackAuditActivity.class, getIntent().getExtras());
    }

    @Override
    public void changePictureSuccess(PictureInfo pictureInfo) {

        mFrontTowedImageId = pictureInfo.id;
    }

    @Override
    public void showVehicleInfo(VehicleInfo info) {
        mPlateNumberInputItemView.setContent(info.railerehicletvplatenumber);
        loadPicture(info.imgdrivingendimage);
        mFrontTowedImageId = info.drivingendimage;
    }

    @Override
    public VehicleInfo getSaveInfo() {
        String plateNumber = mPlateNumberInputItemView.getContent();
        if (TextUtils.isEmpty(plateNumber)) {
            showToast("请输入车牌号");
            return null;
        }
        mVehicleInfo.railerehicletvplatenumber = plateNumber;
        mVehicleInfo.drivingendimage = mFrontTowedImageId;
        return mVehicleInfo;
    }

    @Override
    public void nextAudit() {

        VehicleInfo vehicleInfo = getSaveInfo();
        if (vehicleInfo != null) {
            Bundle bundle = new Bundle();
            bundle.putParcelable(KeyValue.KEY_VEHICLE_INFO, vehicleInfo);
            bundle.putInt(KeyValue.KEY_OPERATE,getIntent().getExtras().getInt(KeyValue.KEY_OPERATE));
            openActivityForResult(VehicleTowedBackAuditActivity.class, bundle);
        }
    }
    @OnClick(R.id.layout_audit_picture_editImageView)
    public void changePicture() {
        VehicleFrontStrategy vehicleFrontStrategy = (VehicleFrontStrategy) pictureStrategyFactory.createStrategy(VehicleFrontStrategy.class);
        pictureContext = new PictureContext(vehicleFrontStrategy);
        pictureContext.selectPhoto(getContext(), new SelectPhotoCallback() {
            @Override
            public void selectPhotoSuccess(SelectPhotoInfo resultInfo) {
                mFrontTowedImageId = resultInfo.pictureId;
                loadPicture(resultInfo.realFileName);
            }

            @Override
            public void selectPhotoFailed() {

            }
        });
    }
}
